
!function(){
	
	//页面的导入效果
	var pageloadbar = $("#load_page .load_bar").loadbar({
		width:"300px",
		height:"10px",
		speed : 700,
		auto : false
	}).loadbar("setValue",40);

	//初始化页面
	$.Ajax.when(
		[
			{url:$.Depath.getURL("Index/menu")},
			{url:$.Depath.getURL("Index/log")},
			{url:$.Depath.getURL("Index/User")}
		],function(data){
			//检查是否具有权限
			if(data[2]['status'] == 0) 
				var uname = data[2]['data']['uname'];
			else
				window.location.href=$.CONFIG.userHost;

			$.CONFIG.MenuView.menuArr = data[0];
			$(".chu_menu").menuView();

			$(".actionbar").actionbar().setTile("user",uname).setContent("user","<ul class='actionbar_user'><li class='user_item logout'><i class='fa fa-sign-out'></i>&nbsp;&nbsp;退出登录</li></ul>");

			$(".breadcrumb").breadcrumb();
			$(".timetree").timetree("操作日志",data[1])
					
			$(document).trigger("Depath");

			pageloadbar.loadbar("finish", function () {
				$("#load_page").animate({height:"0"},"normal",function  () {
					$("#load_page").remove();
					$.toast("success","初始化成功！");
				});
			});
			$.toast.remove("");
		});

	//绑定刷新按钮
	$(document).on('click','[data-refresh]',function  () {
		$(document).trigger("Depath");
	});

	//用户登出事件
    $(document).on('click','.logout',function  () {
    	$.Ajax.getData({url:$.Depath.getURL("Index/logout")},function(data){
    		if(data.status == 0){
    			window.location.href=$.CONFIG.userHost;
    		}
    	});
    });

    //监听自定义事件

    $(document).on("Init",function  (event, data) {
		$.pagedata = data;
		$('[data-tooltip]').tooltip();
		$('[data-loadbar]').loadbar();
		$('[data-tabs]').tabs();
		$('[data-pagination]').pagination({
			item_count:data['data'].item_count
        });
        $('[data-table]').table();
        $('[data-seekbar]').seekbar();
		
			if(data && data.data && data['data'].item_count)
			$('[data-tablekit]').tablekit({
				item_count:data['data'].item_count
			});
		else
			$('[data-table]').table();
		
		$('[data-optionbtn]').optionbtn();
        //图片
        $('a[rel]').foxibox();

        if(data && data.data)
			$('[data-treeview]').menuView(true,'treeview',data.data);


		$("#province").val("13");
		$("#province").trigger("change");
		$("#province2").val("13");
		$("#province2").trigger("change");
		$('.carousel').carousel({ interval:false }); //轮播图初始化
		
		
		KindEditor.each({
					'plug-align' : {
						name : '对齐方式',
						method : {
							'justifyleft' : '左对齐',
							'justifycenter' : '居中对齐',
							'justifyright' : '右对齐'
						}
					},
					'plug-order' : {
						name : '编号',
						method : {
							'insertorderedlist' : '数字编号',
							'insertunorderedlist' : '项目编号'
						}
					},
					'plug-indent' : {
						name : '缩进',
						method : {
							'indent' : '向右缩进',
							'outdent' : '向左缩进'
						}
					}
				},function( pluginName, pluginData ){
					var lang = {};
					lang[pluginName] = pluginData.name;
					KindEditor.lang( lang );
					KindEditor.plugin( pluginName, function(K) {
						var self = this;
						self.clickToolbar( pluginName, function() {
							var menu = self.createMenu({
									name : pluginName,
									width : pluginData.width || 100
								});
							K.each( pluginData.method, function( i, v ){
								menu.addItem({
									title : v,
									checked : false,
									iconClass : pluginName+'-'+i,
									click : function() {
										self.exec(i).hideMenu();
									}
								});
							})
						});
					});
				});
		
						editor=KindEditor.create('#contentqq', {
					themeType : 'qq',
					items : [
						'bold','italic','underline','fontname','fontsize','forecolor','hilitecolor','plug-align','plug-order','plug-indent','link'
					]
				});
				
				

				
		
	});

    /*//处理翻页（目前 翻页绑定了 Table ）  $(document).on('pageChange',function  (event,pageObj)
    $(document).on('tablekit_change',function  (event,pageObj) {
 
    	var current_page = pageObj.options.current_page,
	    		item_everypage = pageObj.options.item_everypage,
				uri = window.location.hash.slice( 1 ),
				uriprasearr = $.Depath.parse(uri),
				table_tmpl = uriprasearr["tmpl"] + "_table",
		        target = pageObj.$element.data("target") || "[data-table]",
		        Url = pageObj.$element.data("url") || $.Depath.getURL(uri,uriprasearr)
				;

				

				var dd=uriprasearr['data'];
				if(dd){
					if(Url.indexOf("?")>0)
					{
						//说明有问号
						for(var k in dd)
						{
							Url+="&"+k+"="+dd[k];
						}
					}else{
						var i=0;
						for(var k in dd)
						{
							if(i==0)
								Url+="?"+k+"="+dd[k];
							else
								Url+="&"+k+"="+dd[k];
							i=i+1;
						}
					}
				}
				

		if(!$.pagedata || !$.pagedata["data"] || !$.pagedata["data"].table){
	 
			$.Ajax.getData({
	    		url:Url,
	    		data : {
	    			current_page : current_page,
	    			item_everypage : item_everypage
	    		}
	    	},function (data) {
	    		//获取模板
	    		var	tmpl = data["data"].table && ( window.QTMPL[table_tmpl] || window.QTMPL['table']);

	    		if(!tmpl) throw new Error("");
	    		tmpl = Handlebars.compile(tmpl);
	    		$(target).html(tmpl(data["data"].table));
	    		$('[data-table]').table();
	    	});	
		}
		else {
			var	tmpl = $.pagedata["data"].table && ( window.QTMPL[table_tmpl] || window.QTMPL['table']);
    		if(!tmpl) throw new Error("No tmpl");
    		tmpl = Handlebars.compile(tmpl);
    		$(target).html(tmpl($.pagedata["data"].table));
    		$('[data-table]').table();
		}
    	$.pagedata = null;
    });*/
	
	
	
	//处理翻页（目前 翻页绑定了 Table ,需要修改）
    $(document).on('tablekit_change',function  (event,tablekit) {
		console.log("nimei");
		var   	 uri = tablekit.url || window.location.hash.slice( 1 ),
			uriprasearr = $.Depath.parse(uri),
			table_tmpl = uriprasearr["tmpl"] + "_table",
	        target = tablekit.target,
	        Url1 = $.Depath.getURL(uri,uriprasearr)
			;
			var Url=window.location.hash;
			console.log("CCC");
			

			param=Url.slice(Url.indexOf('?')+1);

			if(Url.indexOf('?')!=-1&&param!="")
			Url1+='&'+param;
		  //var dd=uriprasearr['data'];
				// if(dd){
				// 	if(Url.indexOf("?")>0)
				// 	{
				// 		//说明有问号
				// 		for(var k in dd)
				// 		{
				// 			Url1+="&"+k+"="+dd[k];
				// 		}
				// 	}else{
				// 		var i=0;
				// 		for(var k in dd)
				// 		{
				// 			if(i==0)
				// 				Url1+="?"+k+"="+dd[k];
				// 			else
				// 				Url1+="&"+k+"="+dd[k];
				// 			i=i+1;
				// 		}
				// 	}
				// }
		
		if(!$.pagedata || !$.pagedata["data"] || !$.pagedata["data"].table){
	    	
			$.Ajax.postData({
	    		url:Url1,
	    		data : tablekit.options
	    	},
	    	"nopath",
	    	function (data) {
	    		//获取模板
	    		var	tmpl = data["data"].table && ( window.QTMPL[table_tmpl] || window.QTMPL['table']);
				console.log(data);
				console.log("init options");
				console.log(tablekit.options);

					tablekit.setOptions({
					item_count:data['data'].item_count,
					item_everypage:tablekit.options['item_everypage']||10,
					current_page:tablekit.options['current_page']
					});


	
				console.log("set options itemcount"+data['data'].item_count);
	    		if(!tmpl) throw new Error("");
	    		tmpl = Handlebars.compile(tmpl);
	    		$(target).html(tmpl(data["data"].table));
	    		$('[data-table]').table();
	    	});
		}
		else {
			var	tmpl = $.pagedata["data"].table && ( window.QTMPL[table_tmpl] || window.QTMPL['table']);
    		if(!tmpl) throw new Error("No tmpl");
    		tmpl = Handlebars.compile(tmpl);
			//console.log($.pagedata["data"].table);
    		$(target).html(tmpl($.pagedata["data"].table));
    		$('[data-table]').table();
		}
    	$.pagedata = null;
    });

	//tabs改变页面
	$(document).on("Tabsindex",function (event,tabsobj) {

		var curLi  = tabsobj.curLi,
			target = tabsobj.target,
			tmplid = tabsobj.tmpl,
			uri = curLi.data("nopath"),
			uriprasearr = $.Depath.parse(uri),
			data = $.Depath.parse(window.location.hash).data
			;
		if ( !target || !tmplid)
			return;
		$.toast.remove("nopath-tabs");
		$.Ajax.abort("nopath-tabs");
		

		$.Ajax.getData({
	    		url: curLi.data("url") || $.Depath.getURL(uri,uriprasearr),
	    		data : $.extend(data,uriprasearr.data)
	    	},
	    	"nopath-tabs",
	    	function (data) {
	    		//获取模板
	    		var	tmpl = $.CONFIG.getTMPL(tmplid);
	    		if(!tmpl) throw new Error("");
	    		$("."+target).html(tmpl(data));
				//Console.log("chart");
				
	    		check_chart(data);
	    	});	
	});
	//绑定机器选中于开关机按钮
	$(document).on("table_check",function (event,table) {
		var length = table.getSelected().length;
		if( length>0 )
			$("[data-vm_op]").removeClass("btn-forbidden");
		else
			$("[data-vm_op]").addClass("btn-forbidden");
	});

	//此处为table的各个选项按钮绑定数据
	$(document).on("table",function  (event, table) {
		var $el = table.element;

		/*$el.find("[data-detail]").each(function  () {
			var $this = $(this);
			$this.data("fdata", {
				id : $this.closest("tr").attr("id")
			});
		});*/

		$el.find("[data-edit]").each(function  () {
			var $this = $(this);
			$this.data("fdata", {
				id : $this.closest("tr").attr("id")
			});
		});

/*		$el.find("[data-delete]").each(function  () {
			var $this = $(this);
			$this.data("fdata", {
				id : $this.closest("tr").attr("id")
			});
		});*/
		$el.find("[data-snapshot]").each(function  () {
			var $this = $(this);
			$this.data("fdata", {
				id : $this.closest("tr").attr("id")
			});
		});
	});

	//坚挺dialog 目的是为了实现dialog 数据绑定 可以放在config.js里
	$(document).on("click", "[data-dialog]",function  () {
		var $this = $(this),
			fdata = $this.data("fdata"),
			nopath = $this.data("nopath"),
			tmpl = $this.data("tmpl"),
			target = $this.closest("[data-dialog]").data("dialog")
			;
		//需要服务器数据的dialog
		if(nopath){
			var Url = $.Depath.getURL( nopath );
			$.Ajax.getData({
			url:Url,
			data:fdata
			},function  (data) {
				//合并本地数据和服务器数据
				data = $.extend(data,fdata);
				tmpl = Handlebars.compile(QTMPL[tmpl]);
				target.setContent(tmpl(data));
			});
		}
		//不需要服务器数据的dialog
		else{
			tmpl = Handlebars.compile(QTMPL[tmpl]);
			target.setContent(tmpl(fdata));
		}
	});
	
	$(document).on("click","[data-toast]",function(){
		var $this = $(this),
			fdata = $this.data("fdata"),
			nopath = $this.data("nopath"),
			tmpl = $this.data("tmpl");
		
			var Url = $.Depath.getURL( nopath );
			$.Ajax.getData({
			url:Url,
			data:fdata
			},function  (data) {
				
			//	console.log("data-toast data:"+data.message);
			if(data.status != 0){
	            $.toast("error",data.message);
	            return;
	        }else{
	             $.toast("success",data.message);
				 //刷新数据
				 setTimeout(function(){$('[data-refresh]').trigger('click');	},1000);
				       
			}	
			});

	});

	// //点击开关机按钮的处理
	// $(document).on('click', '[data-vm_op]',function (event) {
	// 	var poweraction = $(this).data('vm_op'),
	// 		vmlist = $(this).closest('div').find('table').table().getSelected(),
	// 		vmids = []
	// 		;
	// 	for ( var key in vmlist ){
	// 		if ( $(vmlist[key]).attr('id') ){
	// 			vmids.push( $(vmlist[key]).attr('id') );
	// 			$('#'+vmids[key]+" #powerstatus").html('<i class="fa fa-spinner fa-spin"></i>&nbsp;&nbsp;waiting...');
	// 		}
	// 	}
	// 	vmlist = vmids.join(',');
	// 	$.Ajax.postData({
	// 		url:$.Depath.getURL("VM/poweraction"),
	// 		data:{vmids : vmlist,poweraction : poweraction}
	// 	},function (data) {
	// 		if ( data.status == 0 ){
	// 			if ( poweraction == 'on' ){
	// 				for ( var key in vmids ){
	// 					$('#'+vmids[key]+" #powerstatus").text("poweredOn");
	// 				}
	// 			}
	// 			else if ( poweraction == 'off' ){
	// 				for ( var key in vmids ){
	// 					$('#'+vmids[key]+" #powerstatus").text("poweredOff");
	// 				}
	// 			}
	// 		}
	// 	});
	// });

	//三联下拉菜单
	//省
	/*if (!province) {
		var pid = 1;
		$.ajax({
			url: '',
			type: 'POST',
			dataType: 'json',
			data: {pid: pid}
			// async: false,
			// success:function()
		});
	}*/

	$(document).on('change','#province',function () {
		var pid = $('#province').val();
		$("#OutletId").val(pid);
		//alert(pid);
		$('#city').empty();
		$('#town').empty();
		$.ajax({
			type:"POST",
			async:false,
			url:"http://localhost:8080/gd_gdxt/gd_uc/api.php?action=region",
			data:{region_id : pid, region_type: 2},
			dataType:"json",
			success:function(rs){
				changeLoc(rs , "city");
				if(rs.data.length!=0){
					$("#OutletId").val(rs.data[0].region_id);
						$.ajax({
							type:"POST",
							async:false,
							url:"http://localhost:8080/gd_gdxt/gd_uc/api.php?action=region",
							data:{region_id: rs.data[0].region_id, region_type: 3},
							dataType:"json",
							success:function(rs){
								changeLoc(rs , "town");
								if(rs.data.length!=0)
									$("#OutletId").val(rs.data[0].region_id);
							}
						});//ajax
				}

			}
		});
		//changeLoc(rjson , "city");
		
	});
	//市选择改变
	$(document).on('change',"#city",function () {
		var pid = $('#city').val();
		$("#OutletId").val(pid);
		$('#town').empty();
		$.ajax({
			type:"POST",
			async:false,
			url:"http://localhost:8080/gd_gdxt/gd_uc/api.php?action=region",
			data:{region_id: pid, region_type: 3},
			dataType:"json",
			success:function(rs){
				changeLoc(rs , "town");
				//console.log("QQQQQQ");
				//console.log(rs.data[0].region_id);
				if(rs.data.length!=0)
					$("#OutletId").val(rs.data[0].region_id);
			}
		});
		//changeLoc(rjson , "town");
	});
	
	//区选择改变
		$(document).on('change',"#town",function () {
		
		$("#OutletId").val($('#town').val());
		//changeLoc(rjson , "town");
	});
}();


$(document).on('change','#province2',function () {
		var pid = $('#province2').val();
		//$("#OutletId").val(pid);
		//alert(pid);
		$('#city2').empty();
		$('#town2').empty();
		$.ajax({
			type:"POST",
			async:false,
			url:"http://localhost:8080/gd_gdxt/gd_uc/api.php?action=region",
			data:{region_id : pid, region_type: 2},
			dataType:"json",
			success:function(rs){
				changeLoc(rs , "city2");
				if(rs.data.length!=0){
				
				$.ajax({
				type:"POST",
				async:false,
				url:"http://localhost:8080/gd_gdxt/gd_uc/api.php?action=region",
				data:{region_id: rs.data[0].region_id, region_type: 3},
				dataType:"json",
				success:function(rs){
				//console.log("QQQQQQ");
				//console.log(rs.data[0].region_id);
					changeLoc(rs , "town2");
					
				}
			});//ajax
				}

			}
		});
		
		//changeLoc(rjson , "city");
		
	});
	//市选择改变
	$(document).on('change',"#city2",function () {
		var pid = $('#city2').val();
		
		$('#town2').empty();
		$.ajax({
			type:"POST",
			async:false,
			url:"http://localhost:8080/gd_gdxt/gd_uc/api.php?action=region",
			data:{region_id: pid, region_type: 3},
			dataType:"json",
			success:function(rs){
				changeLoc(rs , "town2");
				//console.log("QQQQQQ");
				//console.log(rs.data[0].region_id);
			}
		});	
		//changeLoc(rjson , "town");
	});
	


function changeLoc (rjson , rform) {
	var optionTemp =  '{{#each data}}'
	+ '<option value="{{region_id}}">{{region_name}}</option>'
	+ '{{/each}}';
	//var jsonData = rjson.data;
	
	var varTemp = Handlebars.compile(optionTemp);
	//console.log(varTemp);
	var varHtml = varTemp(rjson);

	$('#'+rform).html(varHtml);
}
//客户名改变 级联更新线路列表
$(document).on('change','#cname',function () {
	var id=$("#cname").val();
			$.ajax({
			type:"POST",
			async:false,
			url:"http://localhost:8080/gd_gdxt/gd_be/api/index/workorder.php?action=lineListByUname",
			data:{uname: id},
			dataType:"json",
			success:function(rs){

				
	var optionTemp =  '{{#each data.table.tr}}'
	+ '<option value="{{Id}}">{{Name}}</option>'
	+ '{{/each}}';
	//var jsonData = rjson.data;
	
	var varTemp = Handlebars.compile(optionTemp);
	//console.log(varTemp);
	var varHtml = varTemp(rs);

	$('#LineId').html(varHtml);
				//console.log("QQQQQQ");
				//console.log(rs.data[0].region_id);

			}
		});
});


//图片和表格切换
    $(document).on('click','.chartOp',function  () {
    	$this=$(this);
    	$(".Line").toggleClass("hide");
    	$("#panel1").toggleClass("hide");
    	$(".chartOp").toggleClass("chartSel");
    });


//评价打分

 $(document).on('click','.comment_score img',function  () {
 		var flags = $(this).attr("alt");
 		$('.comment_score input:hidden[name="score"]').val(flags);
    	$('img').each(function(index, el) {
    		if(index < flags){
    			$(this).attr("src","imgs/s1.gif");
    		}else{
    			$(this).attr("src","imgs/s0.gif");
    		}
    	});
    });


//显示线路描述
 $(document).on('mouseover','.needDescribe',function(e){
		var describe=$(this).find('span.Describe').text();
		if(describe=="")
			describe="暂无描述";
		var tooltip="<div id='tooltip'>"+describe+"</div>";
		$('body').append(tooltip);
		$("#tooltip").css({
			"position":"absolute",
			"top":(e.pageY+20)+"px",
			"left":(e.pageX+20)+"px"
		}).show("fast");
	});
  $(document).on('mouseout','.needDescribe',function(e){
		$("#tooltip").remove();
	});
  $(document).on('mousemove','.needDescribe',function(e){
		$("#tooltip").css({
			"top":(e.pageY+20)+"px",
			"left":(e.pageX+20)+"px"
		});
	});

//分配权限时
  $(document).on('click',"dd [name=access]",function(){
  	if(this.checked)
  		$(this).parents('dl').children('dt').children('input').prop("checked",true);
  });
  $(document).on('click',"dt [name=access]",function(){
  	if(!this.checked)
  		$(this).parents('dl').children('dd').children('input').prop("checked",false);
  });
  
//判断用户名是否存在
$(document).on('blur','[name="ClientName"]',function(){
	
	console.log("clientname blur");
	var name=$("[name='ClientName']").val();
			$.ajax({
			type:"POST",
			async:false,
			url:"http://localhost:8080/gd_gdxt/gd_uc/api.php?action=checkname",
			data:{ClientName:name},
			dataType:"json",
			success:function(rs){
				console.log(rs.data);
	
  
  var tpl="<dl>"+
			"{{#if data}} {{#data}}"+
                "<dt>姓名：</dt>"+
                "<dd>{{uname}}</dd>"+
                "<dt>账户类型：</dt>"+
                "<dd>{{Type}}</dd>"+
                "<dt>邮箱：</dt>"+
                "<dd>{{email}}</dd>"+
                "<dt>注册日期：</dt>"+
                "<dd>{{convertdate register_date}}</dd>"+
                "<dt>上次登录日期：</dt>"+
                "<dd>{{convertdate last_login}}</dd>"+
                "<dt>上次登录IP：</dt>"+
                "<dd>{{last_ip}}</dd> {{/data}}"+
			"{{else}}"+
				"<dt>不存在此用户</dt>"+
			"{{/if}}"+	
          "</dl>";

				
				var template = Handlebars.compile(tpl);
				var html=template(rs);
				console.log(html);
				$("#linecreate_userInfo").html(html); 
				$("#userinfoshow").css('display','block');
			}
		});
});

$(document).on('blur','[data-checkLine]',function(){
	$this=$(this);
	
	
	var name=$this.val();
	
	console.log($this.data("id1"));
	console.log($this.data("id2"));

	
		$.ajax({
			type:"POST",
			async:true,
			url:"http://localhost:8080/gd_gdxt/gd_uc/api.php?action=checkLineByName",
			data:{LineName:name},
			dataType:"json",
			success:function(rs){
				console.log(rs);
	 var tpl="<dl>"+
			"{{#if data}} {{#data}}"+
                "<dt>线路名:</dt><dd>{{Name}}</dd>"+
                "<dt>申请人:</dt><dd>{{uname}}</dd>"+
                "<dt>A端:</dt><dd>{{LineA}}</dd>"+
                "<dt>A端联系人:</dt><dd>{{ALinkMan}}</dd>"+
                "<dt>B端:</dt><dd>{{LineB}}</dd>"+
                "<dt>B端联系人:</dt><dd>{{BLinkMan}}</dd>"+
                "<dt>线路带宽:</dt><dd>{{LineBandWidth}}</dd>"+
                "<dt>线路路由:</dt><dd>{{LineRoute}}</dd>{{/data}}"+
			"{{else}}"+
				"<dt>不存在此线路</dt>"+
			"{{/if}}"+	
          "</dl>";
  				
				var template = Handlebars.compile(tpl);
				var html=template(rs);
				console.log(html);
				$("#"+$this.data("id2")).html(html); 
				$("#"+$this.data("id1")).css('display','block');
 
			}
		});
	
});







//该函数要独立出去
function check_chart ( data ){
	 //是否有图表
    if (data.data && data.data.chart){
    	var charts = data.data.chart;
    	for( var key in charts){
    		var option = charts[key].option,
    			type = option.series[0].type
    			;
    		// 添加toolbox
    		option["toolbox"] = {
				show : true,
				feature : {
					saveAsImage : {show: true}
				}
			};
    		switch (type){
    			//折线型
    			case "line":
    				option.toolbox.feature.magicType = 
    					{show: true, type: ['line', 'bar']};
    				option.tooltip = {
    					show : true,
						trigger: 'axis'
					};
    				break;
    			case "pie":
    				break;
    			case "gauge":
    				break;
    			default:
    				break;
    		}
    		try {
    			echarts.init( $('.' + key)[0] ).setOption(option);
    		}catch (e){
    			$('.' + key).html("<span>" + key + "没数据</span>");
    		}
    	}
    }
}

setDateFilter=function(){
			var $this = $(this),
			option = {},
			key = $this.data("name"),
			val = $this.val(),
			tablekit = $this.closest("[data-tablekit]").data("tablekit")
			;
		dateStart=$("[data-name='searchDateStart']");
		console.log($this);
		console.log("dateStart");
		console.log(dateStart);
		option[key] = val;
		key = dateStart.data("name");
		val = dateStart.val();
		option[key] = val;
		option['current_page']=1;		
		console.log("op");
		console.log(option);
		tablekit.setOptions(option);

		$(document).trigger('tablekit_change',tablekit);
}

jQuery.fn.check_chart=function(data){

	 //是否有图表
    if (data.data && data.data.chart){
    	var charts = data.data.chart;
    	for( var key in charts){
    		var option = charts[key].option,
    			type = option.series[0].type
    			;
    		// 添加toolbox
    		option["toolbox"] = {
				show : true,
				feature : {
					saveAsImage : {show: true}
				}
			};
    		switch (type){
    			//折线型
    			case "line":
    				option.toolbox.feature.magicType = 
    					{show: true, type: ['line', 'bar']};
    				option.tooltip = {
    					show : true,
						trigger: 'axis'
					};
    				break;
    			case "pie":
    				break;
    			case "gauge":
    				break;
    			default:
    				break;
    		}
    		try {
    			echarts.init( $('.' + key)[0] ).setOption(option);
    		}catch (e){
    			$('.' + key).html("<span>" + key + "没数据</span>");
    		}
    	}
    }

}
	//导出Excel
		$(document).on('click','[data-tablekit] [data-exportexcel]',function () {
		var $this = $(this),
			tablekit = $this.closest("[data-tablekit]").data("tablekit")
			;
		tablekit.options['nohandle']== undefined &&(tablekit.options['nohandle'] = 1);
		tablekit.options['nodispatch']== undefined &&(tablekit.options['nodispatch'] = 1);
		tablekit.options['handled']== undefined &&(tablekit.options['handled'] = 1);

		console.log("op");
		console.log(tablekit.options);
		var searchDateEnd=tablekit.options['searchDateEnd']?tablekit.options['searchDateEnd']:"";
		var searchDateStart=tablekit.options['searchDateStart']?tablekit.options['searchDateStart']:"";
		var searchKey=tablekit.options['searchKey']?tablekit.options['searchKey']:"";
		var nohandle=tablekit.options['nohandle'];
		var nodispatch=tablekit.options['nodispatch'];
		var handled=tablekit.options['handled'];
		var Url="http://localhost:8080/gd_gdxt/gd_be/common/test.php";
		 Url=Url+"?searchDateEnd="+searchDateEnd;
		 Url=Url+"&searchDateStart="+searchDateStart;
		 Url=Url+"&searchKey="+searchKey;
		 Url=Url+"&nohandle="+nohandle;
		 Url=Url+"&nodispatch="+nodispatch;
		 Url=Url+"&handled="+handled;
		
		window.open(Url);
		console.log(Url);


	});


		$(document).on('change','#status',function(){
			console.log("change");
			var $this=$(this),
				val=$this.val(),
				tablekit = $this.closest("[data-tablekit]").data("tablekit")
				;


				tablekit.options['nodispatch'] = 0;
				tablekit.options['nohandle'] = 0;					
				tablekit.options['handled'] = 0;
				if(val=="all")
				{
					tablekit.options['nodispatch'] = 1;
					tablekit.options['nohandle'] = 1;					
					tablekit.options['handled'] = 1;
				}
				else
				{
					tablekit.options[val]=1;
				}
			console.log("状态:");
			console.log(tablekit.options);
					
			$(document).trigger('tablekit_change',tablekit);	

		});


		$(document).on('click','[data-tablekit] [data-status]',function(){
			var $this=$(this),
				val=$this.data('val'),
				tablekit = $this.closest("[data-tablekit]").data("tablekit")
				;

			console.log("状态before:");
			console.log(tablekit.options);
			tablekit.options['nohandle']== undefined &&(tablekit.options['nohandle'] = 1);
			tablekit.options['nodispatch']== undefined &&(tablekit.options['nodispatch'] = 1);
			tablekit.options['handled']== undefined &&(tablekit.options['handled'] = 1);
			// tablekit.options['已处理']==undefined&&tablekit.options['已处理']=1;
			// tablekit.options['未调度']==undefined&&tablekit.options['未调度']=1;
			if($this.hasClass('btn-noselect'))
			{
				$this.removeClass('btn-noselect');
				tablekit.options[val]=1;
			}
			else
			{
				$this.addClass('btn-noselect');
				tablekit.options[val]=0;
			}
			tablekit.options['current_page']=1;
			console.log("状态:");
			console.log(tablekit.options);
			$(document).trigger('tablekit_change',tablekit);	
		});
